package com.lzh.seatrend.controller.sms;

import com.lzh.seatrend.common.Result;
import com.lzh.seatrend.common.constant.ResultCode;
import com.lzh.seatrend.service.SmsService;
import com.lzh.seatrend.util.seatrend.RegexUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname SmsController
 * @Description 短信验证api
 * @Date 2021/11/15 11:26
 * @Created by liuzihao
 */
@Api(tags = "短信验证,说明该类的作用", value = "短信验证api")
@RestController
@RequestMapping(value = "/Sms")
public class SmsController {

    private final Logger logger = LoggerFactory.getLogger(SmsController.class);

    @Autowired
    private SmsService smsService;

    @ApiOperation(value = "发送短信验证（说明方法的用途，作用）",notes = "方法的备注说明")
    @ApiImplicitParam(paramType = "String" ,name = "phoneNumber")
    @GetMapping(value = "/sendMsg")
    public Result sendMessage(@RequestParam String phoneNumber){
        logger.info("请求参数: ",phoneNumber);
        boolean isMoble = RegexUtils.checkMobile(phoneNumber);
        if (!isMoble){
            return new Result().setMsg(ResultCode.FAIL);
        }
        return smsService.sendMessageWithTemplate(phoneNumber);
    }
}
